home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0040.dms / q0040.adf / top / top.h < prev    next >
C/C++ Source or Header  |  1990-12-06  |  3KB  |  171 lines

  1. /* Copyright (c) 1988 by Sozobon, Limited.  Author: Tony Andrews
  2.  *
  3.  * Permission is granted to anyone to use this software for any purpose
  4.  * on any computer system, and to redistribute it freely, with the
  5.  * following restrictions:
  6.  * 1) No charge may be made other than reasonable charges for reproduction.
  7.  * 2) Modified versions must be clearly marked as such.
  8.  * 3) The authors are not responsible for any harmful consequences
  9.  *    of using this software, even if they result from defects in it.
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <ctype.h>
  14.  
  15. #include "inst.h"
  16. #include "opcodes.h"
  17.  
  18. #define    DEBUG
  19.  
  20. #ifndef    void
  21. #define    void    int
  22. #endif
  23.  
  24. /*
  25.  * Basic defines and declarations for the optimizer.
  26.  */
  27.  
  28. typedef    int    bool;
  29.  
  30. #ifndef    FALSE
  31. #define    FALSE    0
  32. #define    TRUE    1
  33. #endif
  34.  
  35. /*
  36.  * Basic Block:
  37.  *
  38.  * References a linked list of instructions that make up the block.
  39.  * Each block can be exited via one of two branches, which are
  40.  * represented by pointers to two other blocks, or null.
  41.  */
  42. struct    block {
  43.     int    flags;            /* flags relating to this block */
  44.     int    ref;            /* # of references to this block */
  45.     int    bcode;            /* type of exiting branch */
  46.     char    *name;            /* symbol name that starts the block */
  47.  
  48.     struct    inst    *first,        /* first instruction in block */
  49.             *last;        /* last instruction in block */
  50.  
  51.     /*
  52.      * Execution traversals
  53.      */
  54.     struct    block    *bcond,        /* conditional branch (or NULL) */
  55.             *bfall;        /* "fall through" branch */
  56.  
  57.     /*
  58.      * Logical traversals
  59.      */
  60.     struct    block    *chain;        /* links all blocks together */
  61.     struct    block    *next;        /* next block in the file */
  62.  
  63.     /*
  64.      * Information for data-flow analysis
  65.      */
  66.     int    rref;            /* registers ref'd before set */
  67.     int    rset;            /* registers modified by block */
  68. };
  69.  
  70. typedef    struct block    BLOCK;
  71. typedef    struct inst    INST;
  72.  
  73. /*
  74.  * Block flags
  75.  */
  76.  
  77. #define    B_GLOBAL    0x01        /* is the block's symbol global? */
  78. #define    B_TOUCHED    0x02        /* used in traversals */
  79. #define    B_LABEL        0x04        /* the block needs a label */
  80. #define    B_ISREACHED    0x08        /* block IS reached (for switches) */
  81. #define    B_RET        0x10        /* block terminates with a 'return' */
  82. #define    B_MARK        0x20        /* temporary 'touched' mark */
  83.  
  84. /*
  85.  * Global data
  86.  */
  87.  
  88. extern    FILE    *ifp, *ofp;        /* input and output file pointers */
  89.  
  90. /*
  91.  * Option flags set in main
  92.  */
  93. extern    bool    debug;
  94. extern    bool    do_peep;        /* enable peephole opt. */
  95. extern    bool    do_brev;        /* enable branch reversals */
  96. extern    bool    do_dflow;        /* enable data-flow analysis*/
  97. extern    bool    verbose;
  98.  
  99. /*
  100.  * Optimization stats
  101.  */
  102. extern    int    s_bdel;
  103. extern    int    s_badd;
  104. extern    int    s_brev;
  105. extern    int    s_peep1;
  106. extern    int    s_peep2;
  107. extern    int    s_peep3;
  108. extern    int    s_idel;
  109.  
  110. /*
  111.  * These are set after calling readline.
  112.  */
  113. extern    char    *t_line;    /* text of the last line */
  114. extern    char    *t_lab;        /* label (if any) on the last line */
  115. extern    char    *t_op;        /* opcode */
  116. extern    char    *t_arg;        /* arguments */
  117.  
  118.  
  119. extern    char    *opnames[];    /* mnemonics for the instructions */
  120.  
  121. extern    BLOCK    *fhead;        /* head of the current function */
  122.  
  123. /*
  124.  * Function declarations
  125.  */
  126.  
  127. /*
  128.  * branch.c
  129.  */
  130. extern    void    bopt();
  131.  
  132. /*
  133.  * data.c
  134.  */
  135. extern    int    reg_ref(), reg_set();
  136. extern    bool    sets(), refs(), uses();
  137.  
  138. /*
  139.  * health.c
  140.  */
  141. extern    void    rhealth();
  142.  
  143. /*
  144.  * inst.c
  145.  */
  146. extern    void    addinst(), delinst(), putinst();
  147. extern    bool    opeq();
  148.  
  149. /*
  150.  * io.c
  151.  */
  152. extern    bool    readline();
  153.  
  154. /*
  155.  * peep.c
  156.  */
  157. extern    void    peep();
  158.  
  159. /*
  160.  * util.c
  161.  */
  162. extern    char    *alloc();
  163. extern    char    *strsave();
  164.  
  165. /*
  166.  * sym.c
  167.  */
  168. extern    void    freesym();
  169. extern    BLOCK    *getsym(), *mksym();
  170. extern    char    *mktmp();
  171.